//
//  YYENoteCommentTableViewCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/25.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYENoteCommentTableViewCell.h"

@interface YYENoteCommentTableViewCell ()

@property (nonatomic,strong) UIImageView *headerIV;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UILabel *contentLabel;
@property (nonatomic,strong) UIView *lineView;

@end

@implementation YYENoteCommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.headerIV = [[UIImageView alloc]init];
        self.headerIV.layer.cornerRadius = 10;
        self.headerIV.clipsToBounds = YES;
        [self.contentView addSubview:self.headerIV];
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textColor = [UIColor blackColor];
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.nameLabel];
        
        self.timeLabel = [[UILabel alloc]init];
        self.timeLabel.textColor = LineColor;
        self.timeLabel.textAlignment = NSTextAlignmentRight;
        self.timeLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.timeLabel];
        
        self.contentLabel = [[UILabel alloc]init];
        self.contentLabel.textColor = [UIColor blackColor];
        self.contentLabel.font = [UIFont systemFontOfSize:13];
        self.contentLabel.numberOfLines = 0;
        [self.contentView addSubview:self.contentLabel];
        
        self.lineView = [[UIView alloc]init];
        self.lineView.backgroundColor = LightLineColor;
        [self.contentView addSubview:self.lineView];
        
    }
    return self;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.headerIV makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(24);
        make.top.equalTo(self.contentView.top).offset(8);
        make.size.equalTo(CGSizeMake(20, 20));
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerIV.right).offset(10);
        make.centerY.equalTo(self.headerIV.centerY);
    }];
    
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.right).offset(-16);
        make.centerY.equalTo(self.headerIV.centerY);
    }];
    
    [self.contentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerIV.bottom).offset(7);
//        make.bottom.equalTo(self.contentView.bottom).offset(-11);
        make.left.equalTo(self.contentView.left).offset(20);
        make.right.equalTo(self.contentView.right).offset(-14);
    }];
    
    [self.lineView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(8);
        make.right.equalTo(self.contentView.right).offset(-8);
        make.bottom.equalTo(self.contentView.bottom);
        make.height.equalTo(0.5);
    }];
    
}

- (void)setCommentModel:(YYENoteCommentModel *)commentModel {
    _commentModel = commentModel;
    
    [self.headerIV sd_setImageWithURL:[NSURL URLWithString:commentModel.img] placeholderImage:nil];
    self.nameLabel.text = commentModel.name;
    self.timeLabel.text = commentModel.com_create_at;
    self.contentLabel.text = commentModel.comment;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
